home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / vsrc.tar / voyager7_src / dump.c < prev    next >
C/C++ Source or Header  |  1991-02-27  |  3KB  |  167 lines

  1. /*
  2. // Abstract:
  3. //    DUMP---Dump Memory
  4. //
  5. //    The Dump Memory module provides for the display of the HP 48SX's
  6. //    memory in various formats.
  7. //
  8. // Author:
  9. //    Derek S. Nickel
  10. //
  11. // Creation date:
  12. //    28 October 1990
  13. //
  14. // History:
  15. // V01-001    Derek S. Nickel        28-OCT-1990
  16. //    Original.
  17. //
  18. */
  19.  
  20. #include <ctype.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24.  
  25. #include "dump.h"
  26. #include "memory.h"
  27. #include "modes.h"
  28. #include "pager.h"
  29.  
  30. #define vgr__intlogerr \
  31. "%%VOYAGER-E-INTLOGERR, internal logic error\n"
  32.  
  33. /***********************************************************************
  34.     dump_hex_part
  35. ***********************************************************************/
  36.  
  37. void dump_hex_part(char *buf)
  38. {
  39.     /*
  40.     // Dump the data in FE DC BA 98 76 54 32 10... format.
  41.     */
  42.  
  43.     int j, i;
  44.  
  45.     i = strlen(buf)/2 - 1;
  46.  
  47.     for (j = i; j >= 0; j--)
  48.         printf(" %c%c", buf[2*j+1], buf[2*j]);
  49. }
  50.  
  51. /***********************************************************************
  52.     dump_text_part
  53. ***********************************************************************/
  54.  
  55. void dump_text_part(char *buf)
  56. {
  57.     int j, ch, i;
  58.  
  59.     i = strlen(buf)/2 - 1;
  60.  
  61.     for (j = 0; j <= i; ++j) {
  62.         ch = hexval(buf[2*j]) + (hexval(buf[2*j+1]) << 4);
  63.         if (isprint(ch))
  64.             putchar(ch);
  65.         else
  66.             putchar('.');
  67.     }
  68. }
  69.  
  70. /***********************************************************************
  71.     dump_hex
  72. ***********************************************************************/
  73.  
  74. void dump_hex(void)
  75. {
  76.     /*
  77.     // Dump 32 nibbles (16 characters) with ASCII representation.
  78.     */
  79.  
  80.     char buf[33];
  81.     bin5_t origWP = WorkPtr;
  82.  
  83.     pager(0);
  84.     GetNNibbles(buf,32);
  85.     dump_hex_part(buf);
  86.     putchar(' ');
  87.     dump_text_part(buf);
  88.     printf(" %05lX\n", origWP);
  89. }
  90.  
  91. /***********************************************************************
  92.     dump_text
  93. ***********************************************************************/
  94.  
  95. void dump_text(void)
  96. {
  97.     /*
  98.     // Dump 64 characters (128 nibbles), ASCII representation only.
  99.     */
  100.  
  101.     char buf[129];
  102.     bin5_t origWP = WorkPtr;
  103.  
  104.     pager(0);
  105.     GetNNibbles(buf,128);
  106.     putchar(' ');
  107.     dump_text_part(buf);
  108.     printf(" %05lX\n", origWP);
  109. }
  110.  
  111. /***********************************************************************
  112.     dump_alt
  113. ***********************************************************************/
  114.  
  115. void dump_alt(void)
  116. {
  117.     /*
  118.     // Dump 32 nibbles (16 characters) with ASCII representation.
  119.     // Memory dump format (low to high).
  120.     */
  121.  
  122.     char buf[33];
  123.     bin5_t origWP = WorkPtr;
  124.  
  125.     pager(0);
  126.     GetNNibbles(buf,32);
  127.     printf("%05lX: %s ", origWP, buf);
  128.     dump_text_part(buf);
  129.     putchar('\n');
  130. }
  131.  
  132. /***********************************************************************
  133.     dump_memory
  134. ***********************************************************************/
  135.  
  136. void dump_memory(bin5_t adr, int dump_type)
  137. {
  138.     static int current_dump_type = 1;
  139.     int j, limit = modes.limit;
  140.  
  141.     SetWorkPtr(adr);
  142.  
  143.     if (dump_type != 0) current_dump_type = dump_type;
  144.  
  145.     switch (current_dump_type) {
  146.         case 1:
  147.         for (j = 0; j < limit; j++)
  148.             dump_hex();
  149.         break;
  150.  
  151.         case 2:
  152.         for (j = 0; j < limit; j++)
  153.             dump_text();
  154.         break;
  155.  
  156.         case 3:
  157.         for (j = 0; j < limit; j++)
  158.             dump_alt();
  159.         break;
  160.  
  161.         default:
  162.         pager(0);
  163.         printf(vgr__intlogerr);
  164.         break;
  165.     }
  166. }
  167.